;
(function () {
  new Vue({
    el: '#contract-list',
    data: {
			permissions: JSON.parse(window.localStorage.getItem('permissions')),
      data: {},
      keyword: '',
      beginIntentAmount: null,
      endIntentAmount: null,
      listMenu: [
        { 'name': '未关联', 'code': 'NO' },
        { 'name': '关联客户', 'code': 'KH' },
        { 'name': '关联线索', 'code': 'XS' }        
      ],
			pageCounts: [
				{ 'name': '10', 'code': 10 },
				{ 'name': '15', 'code': 15 },
				{ 'name': '20', 'code': 20 },
			],
      selectedListMenuCode: [],
      currentPage: 1,
      totalPage: 0,
      totalCount: 0,
      limit: ['10'],
      isExtenseFlag: false,
			beginTime: '',
			endtime: '',
			visitorTypeList: [],
			selectVisitorType: [],
			channelTypeData: [],
			selectChannelType: [],
			channelNameData: [],
			selectChannelName: [],
			industryData: [],
			selectIndustry: [],
			areageData: [],
			selectAreage: [],
			projectList: [],
			selectProjectId: [],
			tableData: [],
      isScroll: false,
			
			unitList: [],
			selectUnit: []
    },
    filters: {
      formatDate: function (time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      formatDatehms: function (time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd HH:mm:ss')
      },
      formatUndefined: function (item) {
        if (!item) return '--'
        return item
      },
      formatNum: function (item) {
        if (item === undefined) return '--'
        return hlNumberUtil.formatNum(item)
      }
    },
    created() {
			this.visitorTypeData()
			this.getChannelTypeData()
			this.getIndustry()
			this.areageDebi()
			this.getprojectData()
			this.visitor_form_info()
    },
    methods: {
			exportData () {
				hlhttp.get({
				  baseUrl: exclUrl,
				  url: 'resource/visitor_form_info/list_export',
				  data: {
				    keyword: this.keyword || '#',
				    visitor_form_type: this.selectVisitorType.length ? this.selectVisitorType[0] : '#',
				    channel_category_code: this.selectChannelType.length ? this.selectChannelType[0] : '#',
				    channel_name_code: this.selectChannelName.length ? this.selectChannelName[0] : '#',
				    industry_code: this.selectIndustry.length ? this.selectIndustry[0] : '#',
				    consult_begin_time: this.beginTime || '#',
				    consult_end_time: this.endtime || '#',
				    intent_acreage_code: this.selectAreage.length ? this.selectAreage[0] : '#',
				    project_id: this.selectProjectId.length ? this.selectProjectId[0] : '#',
				    unit_id: this.selectUnit.length ? this.selectUnit[0] : '#',
				    ref_cstmr_type: this.selectedListMenuCode.length ? this.selectedListMenuCode.toString() : '#',
				  },
				  success: (data) => {
				    var a = document.createElement('a');
				    a.href = data.excel_url;
				    $('body').append($(a))
				    a.click();
				    setTimeout(function() {
				      $(a).remove()
				    }, 100);
				
				  }
				})
			},
			toEdit (item) {				
				hlUrlUtil.goTo('intentionalEditor', { ddtab: true, clear: true, id: item.id }, true)
			},
      createyx() {
        hlUrlUtil.goTo('intentionalEditor', { ddtab: true, clear: true }, true)
      },
			toDetail (item) {
				hlUrlUtil.goTo('intentionalDetail', { ddtab: true, clear: true, id: item.id }, true)
			},
			openMore () {
				this.isExtenseFlag = !this.isExtenseFlag
			},
			selectBillMenu () {
				this.visitor_form_info()
			},
			//访客单类型接口
			visitorTypeData () {
				this.visitorTypeList = []
				hlhttp.get({
					url: 'configure/dict',
					data: {
						module_code: 'ZHSH',
						config_name: 'ZS_VISITOR_LIST_TYPE'
					},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.visitorTypeList.push(item)
							}
						})						
					},
				})
			},
			//渠道分类
			getChannelTypeData () {	
				this.channelTypeData = []
			  hlhttp.get({
			    url: 'configure/dict',
			    data: {module_code: 'ZHSH', config_name: 'ZS_CHANNEL_CATE'},
			    success: data => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.channelTypeData.push(item)
							}
						})
			    }
			  })
			},
			//渠道名称
			getChannelNameData () {
				this.channelNameData = []
				this.selectChannelName = []
			  hlhttp.get({
			    url: 'configure/dict',
			    data: {module_code: 'ZHSH', config_name: 'ZS_CHANNEL_NAME', parent_dict_code: this.selectChannelType[0]},
			    success: data => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.channelNameData.push(item)
							}
						})
			    }
			  })
			},
			//所属行业
			getIndustry () {	
				this.industryData = []
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'ZHSH',config_name: 'ZS_INDUSTRY_TYPE'},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.industryData.push(item)
							}
						})
					}
				})
			},
			//面积
			areageDebi () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'ZHSH',config_name: 'ZS_INTENT_AREA'},
					success: (data) => {
						data.map(item => {
							item.code = item.dictCode
							item.name = item.dictName
							if (item.status == 'Y') {
								this.areageData.push(item)
							}
						})
					}
				})
			},
			//获取项目
			getprojectData () {
			  const self  = this
			
			  hlhttp.get({
			    url: 'user/projects',
			    success: (res) => {
						res = hlArrayUtil.removeRepeat(res, 'projectId')
						res.unshift({projectName: '全部', projectId: '#'})
						self.projectList = hlArrayUtil.replaceData(res, [{key: 'projectName', rKey: 'name'}, {key: 'projectId', rKey: 'code'}]);										
			    }
			  })
			},
			
			//获取单元
			unitData () {
				this.selectUnit = []
				hlhttp.get({
					url: 'bu_rent_units/_search',
					data: {
						group_id: '#',
						project_id: this.selectProjectId[0],
						building_id: '#',
						floor_id: '#',
						page: 1,
						unit_type: '#',
						page_size: 100000
					},
					success: (data) => {
						data.units.map(item => {
							item.name = item.unitName
							item.code = item.id
						})
						this.unitList = data.units
					}
				})
			},
			//重置
			resetData () {
				this.keyword = '';
				this.selectVisitorType = [];
				this.selectChannelType = [];
				this.selectChannelName = [];
				this.selectIndustry = [];
				this.beginTime = '';
				this.endtime = '';
				this.selectAreage = [];
				this.selectProjectId = [];
				this.selectedListMenuCode = [];
				this.currentPage = 1;
				this.limit = ['10'];
				this.selectUnit = []
				this.visitor_form_info()
			},
			//获取访客单列表
			visitor_form_info () {
				hlhttp.get({
					url: 'visitor_form_info/_search',
					data: {						
						keyword: this.keyword || '#',
						visitor_form_type: this.selectVisitorType.length ? this.selectVisitorType[0] : '#',
						channel_category_code: this.selectChannelType.length ? this.selectChannelType[0] : '#',
						channel_name_code: this.selectChannelName.length ? this.selectChannelName[0] : '#',
						industry_code: this.selectIndustry.length ? this.selectIndustry[0] : '#',
						consult_begin_time: this.beginTime || '#',
						consult_end_time: this.endtime || '#',
						intent_acreage_code: this.selectAreage.length ? this.selectAreage[0] : '#',
						project_id: this.selectProjectId.length ? this.selectProjectId[0] : '#',
						unit_id: this.selectUnit.length ? this.selectUnit[0] : '#',
						ref_cstmr_type: this.selectedListMenuCode.length ? this.selectedListMenuCode.toString() : '#',
						page: this.currentPage,
						limit: this.limit[0]
					},
					success: (data) => {
						this.tableData = data.data;
						this.totalPage = data.totalPage;
						this.totalCount = data.totalCount;
					}
				})
			},
			//鼠标经过显示scroll
			showScroll() {
			  this.isScroll = true;
			},
			//鼠标离开关闭scroll
			hideScroll() {
			  this.isScroll = false;
			},
		},
    mounted: function () {
      
      
    }
  })

}())
